﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace scmsByAspdNet.cotro.admin {
  /// <summary>
  /// getTeacher 的摘要说明
  /// </summary>
  public class getTeacher : IHttpHandler {

    public void ProcessRequest(HttpContext context) {
      //数据库
      SqlConnection conn = new SqlConnection("Data Source=106.54.69.143;database=scms;uid=sa;pwd=Aspdotnet666");
      conn.Open();
      string ret = "{\"code\":1,\"teachers\":[";
      SqlCommand cmd = new SqlCommand("select id,name,sex,teacher_title,faculty,avatar,intro,is_deleted from sc_teacher;", conn);
      cmd.ExecuteNonQuery();
      SqlDataReader reader = cmd.ExecuteReader();
      for (; reader.Read();) {
        if (reader[7].ToString() == "1") continue;
        ret += $"{{\"id\":{reader[0].ToString()},\"name\":\"{reader[1].ToString()}\",\"sex\":{reader[2].ToString()},\"teacher_title\":\"{reader[3].ToString()}\",\"faculty\":\"{reader[4].ToString()}\",\"avatar\":\"{reader[5].ToString()}\",\"intro\":\"{reader[6].ToString()}\"}},";
      }
      ret = ret.Substring(0, ret.Length - 1);
      ret += "]}";
      conn.Close();
      //返回数据
      context.Response.StatusCode = 200;
      context.Response.Write(ret);
    }

    public bool IsReusable {
      get {
        return false;
      }
    }
  }
}